<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>coordinate3_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_math_coordinate3_test.js.html">coordinate3_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.math.Coordinate3Test&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.math.Coordinate3Test&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.math.Coordinate3&#39;);
<a name="line19"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line20"></a>
<a name="line21"></a>function assertCoordinate3Equals(a, b) {
<a name="line22"></a>  assertTrue(b + &#39; should be equal to &#39; + a,
<a name="line23"></a>             goog.math.Coordinate3.equals(a, b));
<a name="line24"></a>}
<a name="line25"></a>
<a name="line26"></a>
<a name="line27"></a>function testCoordinate3MissingXYZ() {
<a name="line28"></a>  var noXYZ = new goog.math.Coordinate3();
<a name="line29"></a>  assertEquals(0, noXYZ.x);
<a name="line30"></a>  assertEquals(0, noXYZ.y);
<a name="line31"></a>  assertEquals(0, noXYZ.z);
<a name="line32"></a>  assertCoordinate3Equals(noXYZ, new goog.math.Coordinate3());
<a name="line33"></a>}
<a name="line34"></a>
<a name="line35"></a>
<a name="line36"></a>function testCoordinate3MissingYZ() {
<a name="line37"></a>  var noYZ = new goog.math.Coordinate3(10);
<a name="line38"></a>  assertEquals(10, noYZ.x);
<a name="line39"></a>  assertEquals(0, noYZ.y);
<a name="line40"></a>  assertEquals(0, noYZ.z);
<a name="line41"></a>  assertCoordinate3Equals(noYZ, new goog.math.Coordinate3(10));
<a name="line42"></a>}
<a name="line43"></a>
<a name="line44"></a>
<a name="line45"></a>function testCoordinate3MissingZ() {
<a name="line46"></a>  var noZ = new goog.math.Coordinate3(10, 20);
<a name="line47"></a>  assertEquals(10, noZ.x);
<a name="line48"></a>  assertEquals(20, noZ.y);
<a name="line49"></a>  assertEquals(0, noZ.z);
<a name="line50"></a>  assertCoordinate3Equals(noZ, new goog.math.Coordinate3(10, 20));
<a name="line51"></a>}
<a name="line52"></a>
<a name="line53"></a>
<a name="line54"></a>function testCoordinate3IntegerValues() {
<a name="line55"></a>  var intCoord = new goog.math.Coordinate3(10, 20, -19);
<a name="line56"></a>  assertEquals(10, intCoord.x);
<a name="line57"></a>  assertEquals(20, intCoord.y);
<a name="line58"></a>  assertEquals(-19, intCoord.z);
<a name="line59"></a>  assertCoordinate3Equals(intCoord, new goog.math.Coordinate3(10, 20, -19));
<a name="line60"></a>}
<a name="line61"></a>
<a name="line62"></a>
<a name="line63"></a>function testCoordinate3FloatValues() {
<a name="line64"></a>  var floatCoord = new goog.math.Coordinate3(10.5, 20.897, -71.385);
<a name="line65"></a>  assertEquals(10.5, floatCoord.x);
<a name="line66"></a>  assertEquals(20.897, floatCoord.y);
<a name="line67"></a>  assertEquals(-71.385, floatCoord.z);
<a name="line68"></a>  assertCoordinate3Equals(floatCoord,
<a name="line69"></a>      new goog.math.Coordinate3(10.5, 20.897, -71.385));
<a name="line70"></a>}
<a name="line71"></a>
<a name="line72"></a>
<a name="line73"></a>function testCoordinate3OneNonNumericValue() {
<a name="line74"></a>  var dim5 = new goog.math.Coordinate3(&#39;ten&#39;, 1000, 85);
<a name="line75"></a>  assertTrue(isNaN(dim5.x));
<a name="line76"></a>  assertEquals(1000, dim5.y);
<a name="line77"></a>  assertEquals(85, dim5.z);
<a name="line78"></a>}
<a name="line79"></a>
<a name="line80"></a>
<a name="line81"></a>function testCoordinate3AllNonNumericValues() {
<a name="line82"></a>  var nonNumeric = new goog.math.Coordinate3(&#39;ten&#39;,
<a name="line83"></a>                                             {woop: &#39;test&#39;},
<a name="line84"></a>                                             Math.sqrt(-1));
<a name="line85"></a>  assertTrue(isNaN(nonNumeric.x));
<a name="line86"></a>  assertTrue(isNaN(nonNumeric.y));
<a name="line87"></a>  assertTrue(isNaN(nonNumeric.z));
<a name="line88"></a>}
<a name="line89"></a>
<a name="line90"></a>
<a name="line91"></a>function testCoordinate3Origin() {
<a name="line92"></a>  var origin = new goog.math.Coordinate3(0, 0, 0);
<a name="line93"></a>  assertEquals(0, origin.x);
<a name="line94"></a>  assertEquals(0, origin.y);
<a name="line95"></a>  assertEquals(0, origin.z);
<a name="line96"></a>  assertCoordinate3Equals(origin, new goog.math.Coordinate3(0, 0, 0));
<a name="line97"></a>}
<a name="line98"></a>
<a name="line99"></a>
<a name="line100"></a>function testCoordinate3Clone() {
<a name="line101"></a>  var c = new goog.math.Coordinate3();
<a name="line102"></a>  assertCoordinate3Equals(c, c.clone());
<a name="line103"></a>  c.x = -12;
<a name="line104"></a>  c.y = 13;
<a name="line105"></a>  c.z = 5;
<a name="line106"></a>  assertCoordinate3Equals(c, c.clone());
<a name="line107"></a>}
<a name="line108"></a>
<a name="line109"></a>
<a name="line110"></a>function testToString() {
<a name="line111"></a>  assertEquals(&#39;(0, 0, 0)&#39;, new
<a name="line112"></a>               goog.math.Coordinate3().toString());
<a name="line113"></a>  assertEquals(&#39;(1, 0, 0)&#39;, new
<a name="line114"></a>               goog.math.Coordinate3(1).toString());
<a name="line115"></a>  assertEquals(&#39;(1, 2, 0)&#39;, new
<a name="line116"></a>               goog.math.Coordinate3(1, 2).toString());
<a name="line117"></a>  assertEquals(&#39;(0, 0, 0)&#39;, new goog.math.Coordinate3(0, 0, 0).toString());
<a name="line118"></a>  assertEquals(&#39;(1, 2, 3)&#39;, new goog.math.Coordinate3(1, 2, 3).toString());
<a name="line119"></a>  assertEquals(&#39;(-4, 5, -3)&#39;, new goog.math.Coordinate3(-4, 5, -3).toString());
<a name="line120"></a>  assertEquals(&#39;(11.25, -71.935, 2.8)&#39;,
<a name="line121"></a>               new goog.math.Coordinate3(11.25, -71.935, 2.8).toString());
<a name="line122"></a>}
<a name="line123"></a>
<a name="line124"></a>
<a name="line125"></a>function testEquals() {
<a name="line126"></a>  var a = new goog.math.Coordinate3(3, 4, 5);
<a name="line127"></a>  var b = new goog.math.Coordinate3(3, 4, 5);
<a name="line128"></a>  var c = new goog.math.Coordinate3(-3, 4, -5);
<a name="line129"></a>
<a name="line130"></a>  assertTrue(goog.math.Coordinate3.equals(null, null));
<a name="line131"></a>  assertFalse(goog.math.Coordinate3.equals(a, null));
<a name="line132"></a>  assertTrue(goog.math.Coordinate3.equals(a, a));
<a name="line133"></a>  assertTrue(goog.math.Coordinate3.equals(a, b));
<a name="line134"></a>  assertFalse(goog.math.Coordinate3.equals(a, c));
<a name="line135"></a>}
<a name="line136"></a>
<a name="line137"></a>
<a name="line138"></a>function testCoordinate3Distance() {
<a name="line139"></a>  var a = new goog.math.Coordinate3(-2, -3, 1);
<a name="line140"></a>  var b = new goog.math.Coordinate3(2, 0, 1);
<a name="line141"></a>  assertEquals(5, goog.math.Coordinate3.distance(a, b));
<a name="line142"></a>}
<a name="line143"></a>
<a name="line144"></a>
<a name="line145"></a>function testCoordinate3SquaredDistance() {
<a name="line146"></a>  var a = new goog.math.Coordinate3(7, 11, 1);
<a name="line147"></a>  var b = new goog.math.Coordinate3(3, -1, 1);
<a name="line148"></a>  assertEquals(160, goog.math.Coordinate3.squaredDistance(a, b));
<a name="line149"></a>}
<a name="line150"></a>
<a name="line151"></a>
<a name="line152"></a>function testCoordinate3Difference() {
<a name="line153"></a>  var a = new goog.math.Coordinate3(7, 11, 1);
<a name="line154"></a>  var b = new goog.math.Coordinate3(3, -1, 1);
<a name="line155"></a>  assertCoordinate3Equals(goog.math.Coordinate3.difference(a, b),
<a name="line156"></a>                          new goog.math.Coordinate3(4, 12, 0));
<a name="line157"></a>}
<a name="line158"></a>
<a name="line159"></a>
<a name="line160"></a>function testToArray() {
<a name="line161"></a>  var a = new goog.math.Coordinate3(7, 11, 1);
<a name="line162"></a>  var b = a.toArray();
<a name="line163"></a>  assertEquals(b.length, 3);
<a name="line164"></a>  assertEquals(b[0], 7);
<a name="line165"></a>  assertEquals(b[1], 11);
<a name="line166"></a>  assertEquals(b[2], 1);
<a name="line167"></a>
<a name="line168"></a>  var c = new goog.math.Coordinate3(&#39;abc&#39;, &#39;def&#39;, &#39;xyz&#39;);
<a name="line169"></a>  var result = c.toArray();
<a name="line170"></a>  assertTrue(isNaN(result[0]));
<a name="line171"></a>  assertTrue(isNaN(result[1]));
<a name="line172"></a>  assertTrue(isNaN(result[2]));
<a name="line173"></a>}
<a name="line174"></a>
<a name="line175"></a>
<a name="line176"></a>function testFromArray() {
<a name="line177"></a>  var a = [1, 2, 3];
<a name="line178"></a>  var b = goog.math.Coordinate3.fromArray(a);
<a name="line179"></a>  assertEquals(&#39;(1, 2, 3)&#39;, b.toString());
<a name="line180"></a>
<a name="line181"></a>  var c = [1, 2];
<a name="line182"></a>  var d = goog.math.Coordinate3.fromArray(c);
<a name="line183"></a>  assertEquals(&#39;(1, 2, 0)&#39;, d.toString());
<a name="line184"></a>
<a name="line185"></a>  var e = [1];
<a name="line186"></a>  var f = goog.math.Coordinate3.fromArray(e);
<a name="line187"></a>  assertEquals(&#39;(1, 0, 0)&#39;, f.toString());
<a name="line188"></a>
<a name="line189"></a>  var g = [];
<a name="line190"></a>  var h = goog.math.Coordinate3.fromArray(g);
<a name="line191"></a>  assertEquals(&#39;(0, 0, 0)&#39;, h.toString());
<a name="line192"></a>
<a name="line193"></a>  var tooLong = [1, 2, 3, 4, 5, 6];
<a name="line194"></a>  assertThrows(&#39;Error should be thrown attempting to convert an invalid type.&#39;,
<a name="line195"></a>      goog.partial(goog.math.Coordinate3.fromArray, tooLong));
<a name="line196"></a>}
</pre>


</body>
</html>
